Fix SAML RelayState allowlist validation - #4014
Open
joemahady-comm wants to merge 1 commit into
Open
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens SAML IdP-initiated login redirects by validating the RelayState URL against the identity zone’s configured links.logout.whitelist and falling back to a safe default when the target is not allowlisted, preventing open redirect abuse in UAA’s SAML login flow.
Changes:
- Updated
UaaSavedRequestAwareAuthenticationSuccessHandlerto resolveRelayStateredirects viaUaaUrlUtils.findMatchingRedirectUri(...)using the zone’s logout whitelist and a safe fallback. - Added/adjusted unit tests to cover whitelisted vs non-whitelisted
RelayStatebehavior. - Updated SAML integration tests to assert the post-login redirect no longer goes to an external non-whitelisted URL.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
uaa/src/test/java/org/cloudfoundry/identity/uaa/integration/feature/SamlLoginIT.java |
Updates integration assertions to reflect the new safe fallback redirect behavior for non-allowlisted RelayState. |
server/src/test/java/org/cloudfoundry/identity/uaa/web/UaaSavedRequestAwareAuthenticationSuccessHandlerTests.java |
Adds unit coverage for RelayState redirect allowlist behavior (whitelisted vs not whitelisted). |
server/src/main/java/org/cloudfoundry/identity/uaa/web/UaaSavedRequestAwareAuthenticationSuccessHandler.java |
Implements allowlist validation for SAML RelayState redirects using the zone’s configured whitelist and a fallback URL. |
Comment on lines
+50
to
+55
| java.util.List<String> samlRelayStateWhitelist = java.util.Optional.ofNullable( | ||
| org.cloudfoundry.identity.uaa.zone.IdentityZoneHolder.get().getConfig().getLinks().getLogout().getWhitelist() | ||
| ).orElse(java.util.Collections.emptyList()); | ||
| String fallbackUrl = this.getDefaultTargetUrl(); | ||
| String matchingRedirectUri = UaaUrlUtils.findMatchingRedirectUri(samlRelayStateWhitelist, relayState, fallbackUrl); | ||
| this.getRedirectStrategy().sendRedirect(request, response, matchingRedirectUri); |
Comment on lines
+90
to
108
| @Test | ||
| void onAuthenticationSuccess_noSavedRequest_hasRelayStateUrl_whitelisted() throws Exception { | ||
| String redirectUri = "https://test.com/test2"; | ||
| request.setParameter(Saml2ParameterNames.RELAY_STATE, redirectUri); | ||
|
|
||
| org.cloudfoundry.identity.uaa.zone.IdentityZone zone = org.cloudfoundry.identity.uaa.zone.IdentityZoneHolder.get(); | ||
| zone.getConfig().getLinks().getLogout().setWhitelist(java.util.List.of("https://test.com/test2")); | ||
| org.cloudfoundry.identity.uaa.zone.IdentityZoneHolder.set(zone); | ||
|
|
||
| var response = new MockHttpServletResponse(); | ||
| var authentication = mock(Authentication.class); | ||
| handler.onAuthenticationSuccess(request, response, authentication); | ||
|
|
||
| assertThat(response.getRedirectedUrl()).isEqualTo(redirectUri); | ||
|
|
||
| // clean up | ||
| zone.getConfig().getLinks().getLogout().setWhitelist(null); | ||
| org.cloudfoundry.identity.uaa.zone.IdentityZoneHolder.clear(); | ||
| } |
Comment on lines
47
to
+55
| String relayState = UaaStringUtils.getCleanedUserControlString(request.getParameter(Saml2ParameterNames.RELAY_STATE), UaaStringUtils.EMPTY_STRING); | ||
| if (UaaStringUtils.hasText(relayState) && UaaUrlUtils.isUrl(relayState)) { | ||
| log.debug("Redirecting to relayState URI: {}", relayState); | ||
| this.getRedirectStrategy().sendRedirect(request, response, relayState); | ||
| java.util.List<String> samlRelayStateWhitelist = java.util.Optional.ofNullable( | ||
| org.cloudfoundry.identity.uaa.zone.IdentityZoneHolder.get().getConfig().getLinks().getLogout().getWhitelist() | ||
| ).orElse(java.util.Collections.emptyList()); | ||
| String fallbackUrl = this.getDefaultTargetUrl(); | ||
| String matchingRedirectUri = UaaUrlUtils.findMatchingRedirectUri(samlRelayStateWhitelist, relayState, fallbackUrl); | ||
| this.getRedirectStrategy().sendRedirect(request, response, matchingRedirectUri); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: Prevented open redirect vulnerabilities by securely validating the RelayState parameter during SAML authentication.
Details: Updated UaaSavedRequestAwareAuthenticationSuccessHandler to validate the RelayState URL against the links.logout.whitelist configured in the identity zone (using UaaUrlUtils.findMatchingRedirectUri). If the target is not in the allowlist, the application safely falls back to redirecting to the context path root (/).